#!/bin/bash

function mkdir_if_not_exists () {
    local d="$1"
    if [ -f "$d" ]
    then
        echo "$d exists and is a file."
        exit 1
    fi

    if [ ! -e "$d" ]
    then
        mkdir "$d"
    fi
}

function file_exists_or_die () {
	local f="$1"
	if [ ! -f "$f" ]
	then
		echo "$f not found!"
		exit 1
	fi
}

function dir_exists_or_die () {
	local d="$1"
	if [ ! -d "$d" ]
	then
		echo "$d not found!"
		exit 1
	fi
}

function is_mount_point() {
    local d="$1"
    local tgts=( $( mount | grep "$d" |awk '{print $3}' ) )
    for tgt in ${tgts}
    do
        if [ "${tgt}" == "$d" ]
        then
            return 0
        fi
    done
    return 1
}
